package webservices;

import interfaces.IMessageManage;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import webservices.helper.Helper;

public class MessageManageImpl implements IMessageManage {
	
	public String add(String courseID, String userID, String subject, String content){
		String returnMessage = "";
		Connection con = null;
		try {
			con = Helper.getDBConnection();
			
			PreparedStatement pst = con.prepareStatement("insert into message(subject, content, createtime, courseid, userid) values(null, ?, now(), ?, ?)");
			pst.setString(1, content);
			pst.setString(2, courseID);
			pst.setString(3, userID);
			pst.executeUpdate();
			returnMessage = "<response name='success' />";
		} catch (SQLException e) {
			e.printStackTrace();
			returnMessage = "<response name='fail' value ='消息添加失败：" + e.getLocalizedMessage() + "' />";
		} finally {
			try{
				con.close();
			}catch(SQLException e) {}
		}
		return returnMessage;
	}
	
}